
<div th:fragment="common-export">
<meta charset="UTF-8" />
<meta http-equiv="pragma" content="no-cache"></meta>
<meta http-equiv="cache-control" content="no-cache"></meta>
<meta http-equiv="expires" content="0"></meta>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script type="text/javascript">
var selectionIds = []; //保存选中id
var FieldId ; //当前页面的主键ID名称
/**选中方法*/
function SelectCheckBox(id, tableId, updateBtn, opt){
		FieldId = id;
		//选中事件操作数组 
		var union = function(array,ids){ 
			$.each(ids, function (i, id) { 
				if($.inArray(id,array)==-1){ 
					array[array.length] = id; 
				} 
			}); 
			return array; 
		}; 
		//取消选中事件操作数组 
		var difference = function(array,ids){ 
			$.each(ids, function (i, id) { 
				var index = $.inArray(id,array); 
				if(index!=-1){ 
					array.splice(index, 1); 
				} 
			}); 
			return array; 
		}; 
		var selectEvents = function(type,rows){ 
			var ids = $.map(!$.isArray(rows) ? [rows] : rows, function (row) { 
		   		return row[FieldId]; 
		  	}); 
		  	func = $.inArray(type, ["check", "check-all"]) > -1 ? "union" : "difference"; 
		  	selectionIds = _[func](selectionIds, ids); 
		  	/**判断更新按钮是否可用*/
		  	if(selectionIds.length == 1){
		  		/**将选中行数据赋值给更新按钮*/
		  		
		  		var ary = $("#" + tableId).datagrid("getSelections");
		  		if(ary.length > 0){
		  			$(ary).each(function(index, obj){
		  				if(selectionIds[0] == obj[FieldId]){
							$("#" + updateBtn).data("info", obj);
							return false;
		  				}
		  			});
		  		}
		  		$("#" + updateBtn).removeAttr("disabled");
		  	}else{
		  		//$("#" + updateBtn).attr("disabled", "disabled");
		  	}
		 } 
		var _ = {"union":union,"difference":difference,"selectEvents":selectEvents}; 
		
		opt.onSelect = function(index,row){_["selectEvents"]("check",row); };
		opt.onUnselect = function(index,row){_["selectEvents"]("uncheck",row); };
		opt.onSelectAll = function(rows){_["selectEvents"]("check-all",rows);};
		opt.onUnselectAll = function(rows){_["selectEvents"]("uncheck-all",rows);};
		return opt;
//		$("#" + tableId).datagrid(opt);
		
}


//绑定选中事件、取消事件、全部选中、全部取消 


//表格分页之前处理多选框数据 
/* function responseHandler(res) {
	$.each(res.rows, function (i, row) { 
		row.checkStatus = true;//$.inArray(row[FieldId], selectionIds) != -1; //判断当前行的数据id是否存在与选中的数组，存在则将多选框状态变为true 
	}); 
	return res; 
} */

</script>
</div>